<template>
  <div
    :style="{'justify-content': textStyle.justifyContent}"
    class="position-full flex-center">
    <!--保留空格-->
    <pre :style="{ ...textStyle}">{{state.values.text}}</pre>
  </div>
</template>
<script>
  import {formatColor} from '@/utils';
  import {mapState} from 'vuex';
  import {WidgetText} from "@/modules/IDE/widget/atom/widgetText";

  export default {
    name: 'TextWidget',
    props: {
      widget: {
        type: WidgetText,
        default: () => {
          return {};
        }
      }
    },
    data() {
      return {};
    },
    computed: {
      ...mapState({
        activeTheme: state => state.ide.activeTheme,
      }),
      state() {
        if (!this.widget || !this.widget.UI.state) return;
        return this.widget.getCurrentState();
      },
      textStyle() {
        const {textStyle = {}} = this.state;
        const textStyles = {};
        // 字体
        const {size, color, weight, align} = textStyle;
	      size && (textStyles.fontSize = `${size}px`);
        color && (textStyles.color = formatColor(color, this.activeTheme));
        weight && (textStyles.fontWeight = weight);
				switch (align) {
				  case 'center':
					  textStyles.justifyContent = 'center';
				    break;
				  case 'left':
					  textStyles.justifyContent = 'flex-start';
				    break;
				  case 'right':
					  textStyles.justifyContent = 'flex-end';
				    break;
				  default:
					  textStyles.justifyContent = 'center';
				    break;
				}
        return textStyles;
      },
    },
  };
</script>

<style scoped>

  .flex-center {
    display: flex;
    align-items: center;
    overflow: hidden;
  }

  pre {
    margin: 0;
    font-size: 14px;
    white-space: pre-wrap;
    word-wrap: break-word;
    word-break: break-all;
  }
</style>
